<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="javax.jdo.Query"%>
<%@page import="de.upb.messerschmidt.set.entity.Location"%>
<%@page import="de.upb.messerschmidt.set.jdo.PMF"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Event Registration</title>
</head>

<body>
	<h1>Event Registration</h1>
	<p>Please enter the event information and submit by pressing the
		button</p>
	<form action="post/event" method="post">
		<!-- Locations mit JSP abrufen -->
		<table>
			<tr>
				<td>Location:</td>
				<td><select name="location" size="1">
						<%
							PersistenceManager pm = PMF.get().getPersistenceManager();
							Query query = pm.newQuery(Location.class);
							query.setOrdering("name desc");
							try {
								@SuppressWarnings("unchecked")
								List<Location> results = (List<Location>) query.execute();
								if (!results.isEmpty()) {
									for (Location l : results) {
						%>
						<option>
							<%=l.getName()%>
						</option>
						<%
							}
								}
							}

							catch (Exception e) {
								e.printStackTrace();
							}
						%>
				</select>
				</td>
			</tr>
			<tr>
				<%
					// This snippets creates the current date
					Date date = new Date();
					String day = date.getDate() + "";
					if (Integer.parseInt(day) < 10)
						day = "0" + day;
					String month = date.getMonth() + 1 + "";
					if (Integer.parseInt(month) < 10)
						month = "0" + month;
					String year = (date.getYear() + 1900) + "";
					String valueString = "value = \"" + day + "." + month + "." + year
							+ "\"";
				%>
				<td>Date:</td>
				<td><input type="text" name="date" <%=valueString%> size="10"
					maxlength="10" /></td>
			</tr>
			<tr>
				<td>Title:</td>
				<td><input type="text" name="title" size="50" /></td>
			</tr>
			<tr>
				<td>Description:</td>
				<td><textarea name="description" cols=50 rows=6></textarea></td>
			</tr>
			<tr>
				<td><input type="submit" value="Submit" />
				</td>
				<td><input type="reset" value="Reset">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
